package com.zzsy.carosshopprojects.activitys.home.mainpage.orderamount;

import android.content.Context;
import com.king.base.util.ToastUtils;
import com.zzsy.carosshopprojects.base.BaseViewMode;
import com.zzsy.carosshopprojects.bean.OrderBean;
import com.zzsy.carosshopprojects.bean.OrderZongBean;
import com.zzsy.carosshopprojects.network.RequestUtils;
import com.zzsy.carosshopprojects.network.Utils.MyObserver;
import com.zzsy.carosshopprojects.util.DataUtil;

import java.util.List;

import androidx.lifecycle.MutableLiveData;

public class OrderAmountMode extends BaseViewMode {
    private MutableLiveData< List<OrderBean.OrdersBean>> liveData;
    private MutableLiveData<OrderZongBean> liveDataOz;

    public MutableLiveData< List<OrderBean.OrdersBean>> getLiveData() {
        if (liveData == null)
            liveData = new MutableLiveData<>();
        return liveData;
    }

    public MutableLiveData<OrderZongBean> getLiveDataOz() {
        if (liveDataOz == null)
            liveDataOz = new MutableLiveData<>();
        return liveDataOz;
    }

    /**
     * 获取订单列表数据
     *
     * @param context
     * @param page
     */
    public void getOrdersByTerminalId(Context context, String page,boolean isShowDialog) {
        RequestUtils.OrdersByTerminalId(context, page, DataUtil.getInstance().getTerminalId(), new MyObserver<OrderBean>(context,isShowDialog) {
            @Override
            public void onSuccess(OrderBean result) {

                liveData.postValue(result.getOrders());
            }

            @Override
            public void onFailure(Throwable e, String errorMsg, int code) {
                ToastUtils.showToast(context.getApplicationContext(), errorMsg);
                liveData.postValue(null);
            }
        });
    }

    /**
     * 获取本班各支付类型支付的金额
     *
     * @param context
     */
    public void geShiftStatisticsByTerminalId(Context context) {
        RequestUtils.ShiftStatisticsByTerminalId(context, DataUtil.getInstance().getTerminalId(), new MyObserver<OrderZongBean>(context,false) {
            @Override
            public void onSuccess(OrderZongBean result) {
                liveDataOz.postValue(result);
            }

            @Override
            public void onFailure(Throwable e, String errorMsg, int code) {
                ToastUtils.showToast(context.getApplicationContext(), errorMsg);
            }
        });
    }
}
